/**
 *
 */
import Util;
import OSS;
import OpenPlatform;
import OSSUtil;
import FileForm;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('threedvision', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model EstimateMonocularImageDepthRequest {
  imageURL?: string(name='ImageURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/zhangchaorun/test-api/xxxx.png'),
}

model EstimateMonocularImageDepthAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/zhangchaorun/test-api/xxxx.png'),
}

model EstimateMonocularImageDepthResponseBody = {
  data?: {
    depthMapUrl?: string(name='DepthMapUrl', example='http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/DepthPrediction/da6ef49a-afef-43c8-8855-4827cde7c152/depth.png'),
    depthToColorUrl?: string(name='DepthToColorUrl', example='http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/DepthPrediction/da6ef49a-afef-43c8-8855-4827cde7c152/color.png'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='FC938F5D-0AD0-5A59-BCE8-D8BE1B3E606F'),
}

model EstimateMonocularImageDepthResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: EstimateMonocularImageDepthResponseBody(name='body'),
}

async function estimateMonocularImageDepthWithOptions(request: EstimateMonocularImageDepthRequest, runtime: Util.RuntimeOptions): EstimateMonocularImageDepthResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'EstimateMonocularImageDepth',
    version = '2021-01-31',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function estimateMonocularImageDepth(request: EstimateMonocularImageDepthRequest): EstimateMonocularImageDepthResponse {
  var runtime = new Util.RuntimeOptions{};
  return estimateMonocularImageDepthWithOptions(request, runtime);
}

async function estimateMonocularImageDepthAdvance(request: EstimateMonocularImageDepthAdvanceRequest, runtime: Util.RuntimeOptions): EstimateMonocularImageDepthResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'threedvision',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var estimateMonocularImageDepthReq = new EstimateMonocularImageDepthRequest{};
  OpenApiUtil.convert(request, estimateMonocularImageDepthReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    estimateMonocularImageDepthReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var estimateMonocularImageDepthResp = estimateMonocularImageDepthWithOptions(estimateMonocularImageDepthReq, runtime);
  return estimateMonocularImageDepthResp;
}

model EstimateMonocularVideoDepthRequest {
  sampleRate?: string(name='SampleRate', example='10'),
  videoURL?: string(name='VideoURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/Estimate.mp4'),
}

model EstimateMonocularVideoDepthAdvanceRequest {
  sampleRate?: string(name='SampleRate', example='10'),
  videoURLObject?: readable(name='VideoURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/Estimate.mp4'),
}

model EstimateMonocularVideoDepthResponseBody = {
  data?: {
    depthUrl?: string(name='DepthUrl', example='http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/VideoDepthPrediction/5c36dc69-2937-440e-ac34-67a00651a753/depths.npy'),
    depthVisUrl?: string(name='DepthVisUrl', example='http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/VideoDepthPrediction/5c36dc69-2937-440e-ac34-67a00651a753/depths_vis.avi'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='E335106F-9F96-491D-AEB3-1610F8545968'),
}

model EstimateMonocularVideoDepthResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: EstimateMonocularVideoDepthResponseBody(name='body'),
}

async function estimateMonocularVideoDepthWithOptions(request: EstimateMonocularVideoDepthRequest, runtime: Util.RuntimeOptions): EstimateMonocularVideoDepthResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.sampleRate)) {
    body['SampleRate'] = request.sampleRate;
  }
  if (!Util.isUnset(request.videoURL)) {
    body['VideoURL'] = request.videoURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'EstimateMonocularVideoDepth',
    version = '2021-01-31',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function estimateMonocularVideoDepth(request: EstimateMonocularVideoDepthRequest): EstimateMonocularVideoDepthResponse {
  var runtime = new Util.RuntimeOptions{};
  return estimateMonocularVideoDepthWithOptions(request, runtime);
}

async function estimateMonocularVideoDepthAdvance(request: EstimateMonocularVideoDepthAdvanceRequest, runtime: Util.RuntimeOptions): EstimateMonocularVideoDepthResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'threedvision',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var estimateMonocularVideoDepthReq = new EstimateMonocularVideoDepthRequest{};
  OpenApiUtil.convert(request, estimateMonocularVideoDepthReq);

  if(!Util.isUnset(request.videoURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.videoURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    estimateMonocularVideoDepthReq.videoURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var estimateMonocularVideoDepthResp = estimateMonocularVideoDepthWithOptions(estimateMonocularVideoDepthReq, runtime);
  return estimateMonocularVideoDepthResp;
}

model EstimateStereoImageDepthRequest {
  leftImageURL?: string(name='LeftImageURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/test/left.png'),
  rightImageURL?: string(name='RightImageURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/test/right.png'),
}

model EstimateStereoImageDepthAdvanceRequest {
  leftImageURLObject?: readable(name='LeftImageURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/test/left.png'),
  rightImageURLObject?: readable(name='RightImageURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/test/right.png'),
}

model EstimateStereoImageDepthResponseBody = {
  data?: {
    disparityMapURL?: string(name='DisparityMapURL', example='http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/StereoDepthPrediction/972ebf03-bd8c-47f6-9281-383fef3fff09/disparity.npy'),
    disparityVisURL?: string(name='DisparityVisURL', example='http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/StereoDepthPrediction/972ebf03-bd8c-47f6-9281-383fef3fff09/disparity.png'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='8B69644C-4815-476B-B087-340BAADE8E35'),
}

model EstimateStereoImageDepthResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: EstimateStereoImageDepthResponseBody(name='body'),
}

async function estimateStereoImageDepthWithOptions(request: EstimateStereoImageDepthRequest, runtime: Util.RuntimeOptions): EstimateStereoImageDepthResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.leftImageURL)) {
    body['LeftImageURL'] = request.leftImageURL;
  }
  if (!Util.isUnset(request.rightImageURL)) {
    body['RightImageURL'] = request.rightImageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'EstimateStereoImageDepth',
    version = '2021-01-31',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function estimateStereoImageDepth(request: EstimateStereoImageDepthRequest): EstimateStereoImageDepthResponse {
  var runtime = new Util.RuntimeOptions{};
  return estimateStereoImageDepthWithOptions(request, runtime);
}

async function estimateStereoImageDepthAdvance(request: EstimateStereoImageDepthAdvanceRequest, runtime: Util.RuntimeOptions): EstimateStereoImageDepthResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'threedvision',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var estimateStereoImageDepthReq = new EstimateStereoImageDepthRequest{};
  OpenApiUtil.convert(request, estimateStereoImageDepthReq);

  if(!Util.isUnset(request.leftImageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.leftImageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    estimateStereoImageDepthReq.leftImageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  if(!Util.isUnset(request.rightImageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.rightImageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    estimateStereoImageDepthReq.rightImageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var estimateStereoImageDepthResp = estimateStereoImageDepthWithOptions(estimateStereoImageDepthReq, runtime);
  return estimateStereoImageDepthResp;
}

model GetAsyncJobResultRequest {
  jobId?: string(name='JobId', example='B6590005-5E7C-4A25-8F97-4479888D8271'),
}

model GetAsyncJobResultResponseBody = {
  data?: {
    errorCode?: string(name='ErrorCode', example='InvalidParameter'),
    errorMessage?: string(name='ErrorMessage', example='paramsIllegal'),
    jobId?: string(name='JobId', example='B6590005-5E7C-4A25-8F97-4479888D8271'),
    result?: string(name='Result', example='{\\"pointCloudUrl\\":\\"http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/MultiviewStereo/83e2fcec-02e1-4522-8680-92f532956e2c/cas_input.ply\\"}'),
    status?: string(name='Status', example='PROCESS_SUCCESS'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='E335106F-9F96-491D-AEB3-1610F8545968'),
}

model GetAsyncJobResultResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetAsyncJobResultResponseBody(name='body'),
}

async function getAsyncJobResultWithOptions(request: GetAsyncJobResultRequest, runtime: Util.RuntimeOptions): GetAsyncJobResultResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetAsyncJobResult',
    version = '2021-01-31',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getAsyncJobResult(request: GetAsyncJobResultRequest): GetAsyncJobResultResponse {
  var runtime = new Util.RuntimeOptions{};
  return getAsyncJobResultWithOptions(request, runtime);
}

model ReconstructBodyBySingleImageRequest {
  imageURL?: string(name='ImageURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/test/yefeibg.png'),
}

model ReconstructBodyBySingleImageAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/test/yefeibg.png'),
}

model ReconstructBodyBySingleImageResponseBody = {
  data?: {
    depthURL?: string(name='DepthURL', example='http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/HumanReconstruction/1ac0e56e-5138-40ea-a44d-05810b57c723/depth.npy'),
    meshURL?: string(name='MeshURL', example='http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/HumanReconstruction/1ac0e56e-5138-40ea-a44d-05810b57c723/mesh.obj'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='D755F706-B33B-4F3B-8751-4707AD2CA15C'),
}

model ReconstructBodyBySingleImageResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ReconstructBodyBySingleImageResponseBody(name='body'),
}

async function reconstructBodyBySingleImageWithOptions(request: ReconstructBodyBySingleImageRequest, runtime: Util.RuntimeOptions): ReconstructBodyBySingleImageResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ReconstructBodyBySingleImage',
    version = '2021-01-31',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function reconstructBodyBySingleImage(request: ReconstructBodyBySingleImageRequest): ReconstructBodyBySingleImageResponse {
  var runtime = new Util.RuntimeOptions{};
  return reconstructBodyBySingleImageWithOptions(request, runtime);
}

async function reconstructBodyBySingleImageAdvance(request: ReconstructBodyBySingleImageAdvanceRequest, runtime: Util.RuntimeOptions): ReconstructBodyBySingleImageResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'threedvision',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var reconstructBodyBySingleImageReq = new ReconstructBodyBySingleImageRequest{};
  OpenApiUtil.convert(request, reconstructBodyBySingleImageReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    reconstructBodyBySingleImageReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var reconstructBodyBySingleImageResp = reconstructBodyBySingleImageWithOptions(reconstructBodyBySingleImageReq, runtime);
  return reconstructBodyBySingleImageResp;
}

model ReconstructThreeDMultiViewRequest {
  mode?: string(name='Mode', example='1'),
  zipFileUrl?: string(name='ZipFileUrl', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/tiyan/mvs_input.zip'),
}

model ReconstructThreeDMultiViewAdvanceRequest {
  mode?: string(name='Mode', example='1'),
  zipFileUrlObject?: readable(name='ZipFileUrl', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/xxxx/tiyan/mvs_input.zip'),
}

model ReconstructThreeDMultiViewResponseBody = {
  data?: {
    pointCloudURL?: string(name='PointCloudURL', example='http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/MultiviewStereo/83e2fcec-02e1-4522-8680-92f532956e2c/cas_input.ply'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='E335106F-9F96-491D-AEB3-1610F8545968'),
}

model ReconstructThreeDMultiViewResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ReconstructThreeDMultiViewResponseBody(name='body'),
}

async function reconstructThreeDMultiViewWithOptions(request: ReconstructThreeDMultiViewRequest, runtime: Util.RuntimeOptions): ReconstructThreeDMultiViewResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.mode)) {
    body['Mode'] = request.mode;
  }
  if (!Util.isUnset(request.zipFileUrl)) {
    body['ZipFileUrl'] = request.zipFileUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ReconstructThreeDMultiView',
    version = '2021-01-31',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function reconstructThreeDMultiView(request: ReconstructThreeDMultiViewRequest): ReconstructThreeDMultiViewResponse {
  var runtime = new Util.RuntimeOptions{};
  return reconstructThreeDMultiViewWithOptions(request, runtime);
}

async function reconstructThreeDMultiViewAdvance(request: ReconstructThreeDMultiViewAdvanceRequest, runtime: Util.RuntimeOptions): ReconstructThreeDMultiViewResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'threedvision',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var reconstructThreeDMultiViewReq = new ReconstructThreeDMultiViewRequest{};
  OpenApiUtil.convert(request, reconstructThreeDMultiViewReq);

  if(!Util.isUnset(request.zipFileUrlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.zipFileUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    reconstructThreeDMultiViewReq.zipFileUrl = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var reconstructThreeDMultiViewResp = reconstructThreeDMultiViewWithOptions(reconstructThreeDMultiViewReq, runtime);
  return reconstructThreeDMultiViewResp;
}

